package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.SysSettings;
import com.xjgzinfo.usdp.repository.SysSettingsRepository;
import com.xjgzinfo.usdp.service.SysSettingsService;
import com.xjgzinfo.usdp.service.dto.SysSettingsDTO;
import com.xjgzinfo.usdp.service.mapper.SysSettingsMapper;
import com.xjgzinfo.usdp.service.dto.SysSettingsCriteria;
import com.xjgzinfo.usdp.service.SysSettingsQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link SysSettingsResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class SysSettingsResourceIT {

    private static final String DEFAULT_SITE_TITLE = "AAAAAAAAAA";
    private static final String UPDATED_SITE_TITLE = "BBBBBBBBBB";

    private static final String DEFAULT_HERDER_TITLE = "AAAAAAAAAA";
    private static final String UPDATED_HERDER_TITLE = "BBBBBBBBBB";

    private static final String DEFAULT_HERDER_LOGO = "AAAAAAAAAA";
    private static final String UPDATED_HERDER_LOGO = "BBBBBBBBBB";

    private static final String DEFAULT_LOCALE = "AAAAAAAAAA";
    private static final String UPDATED_LOCALE = "BBBBBBBBBB";

    private static final String DEFAULT_TIME_ZONE = "AAAAAAAAAA";
    private static final String UPDATED_TIME_ZONE = "BBBBBBBBBB";

    private static final byte[] DEFAULT_OTHER = TestUtil.createByteArray(1, "0");
    private static final byte[] UPDATED_OTHER = TestUtil.createByteArray(1, "1");
    private static final String DEFAULT_OTHER_CONTENT_TYPE = "image/jpg";
    private static final String UPDATED_OTHER_CONTENT_TYPE = "image/png";

    private static final Long DEFAULT_TENANT_ID = 1L;
    private static final Long UPDATED_TENANT_ID = 2L;
    private static final Long SMALLER_TENANT_ID = 1L - 1L;

    @Autowired
    private SysSettingsRepository sysSettingsRepository;

    @Autowired
    private SysSettingsMapper sysSettingsMapper;

    @Autowired
    private SysSettingsService sysSettingsService;

    @Autowired
    private SysSettingsQueryService sysSettingsQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restSysSettingsMockMvc;

    private SysSettings sysSettings;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static SysSettings createEntity(EntityManager em) {
        SysSettings sysSettings = new SysSettings()
            .siteTitle(DEFAULT_SITE_TITLE)
            .herderTitle(DEFAULT_HERDER_TITLE)
            .herderLogo(DEFAULT_HERDER_LOGO)
            .locale(DEFAULT_LOCALE)
            .timeZone(DEFAULT_TIME_ZONE)
            .other(DEFAULT_OTHER)
            .otherContentType(DEFAULT_OTHER_CONTENT_TYPE)
            .tenantId(DEFAULT_TENANT_ID);
        return sysSettings;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static SysSettings createUpdatedEntity(EntityManager em) {
        SysSettings sysSettings = new SysSettings()
            .siteTitle(UPDATED_SITE_TITLE)
            .herderTitle(UPDATED_HERDER_TITLE)
            .herderLogo(UPDATED_HERDER_LOGO)
            .locale(UPDATED_LOCALE)
            .timeZone(UPDATED_TIME_ZONE)
            .other(UPDATED_OTHER)
            .otherContentType(UPDATED_OTHER_CONTENT_TYPE)
            .tenantId(UPDATED_TENANT_ID);
        return sysSettings;
    }

    @BeforeEach
    public void initTest() {
        sysSettings = createEntity(em);
    }

    @Test
    @Transactional
    public void createSysSettings() throws Exception {
        int databaseSizeBeforeCreate = sysSettingsRepository.findAll().size();
        // Create the SysSettings
        SysSettingsDTO sysSettingsDTO = sysSettingsMapper.toDto(sysSettings);
        restSysSettingsMockMvc.perform(post("/api/sys-settings").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(sysSettingsDTO)))
            .andExpect(status().isCreated());

        // Validate the SysSettings in the database
        List<SysSettings> sysSettingsList = sysSettingsRepository.findAll();
        assertThat(sysSettingsList).hasSize(databaseSizeBeforeCreate + 1);
        SysSettings testSysSettings = sysSettingsList.get(sysSettingsList.size() - 1);
        assertThat(testSysSettings.getSiteTitle()).isEqualTo(DEFAULT_SITE_TITLE);
        assertThat(testSysSettings.getHerderTitle()).isEqualTo(DEFAULT_HERDER_TITLE);
        assertThat(testSysSettings.getHerderLogo()).isEqualTo(DEFAULT_HERDER_LOGO);
        assertThat(testSysSettings.getLocale()).isEqualTo(DEFAULT_LOCALE);
        assertThat(testSysSettings.getTimeZone()).isEqualTo(DEFAULT_TIME_ZONE);
        assertThat(testSysSettings.getOther()).isEqualTo(DEFAULT_OTHER);
        assertThat(testSysSettings.getOtherContentType()).isEqualTo(DEFAULT_OTHER_CONTENT_TYPE);
        assertThat(testSysSettings.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
    }

    @Test
    @Transactional
    public void createSysSettingsWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = sysSettingsRepository.findAll().size();

        // Create the SysSettings with an existing ID
        sysSettings.setId(1L);
        SysSettingsDTO sysSettingsDTO = sysSettingsMapper.toDto(sysSettings);

        // An entity with an existing ID cannot be created, so this API call must fail
        restSysSettingsMockMvc.perform(post("/api/sys-settings").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(sysSettingsDTO)))
            .andExpect(status().isBadRequest());

        // Validate the SysSettings in the database
        List<SysSettings> sysSettingsList = sysSettingsRepository.findAll();
        assertThat(sysSettingsList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void getAllSysSettings() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList
        restSysSettingsMockMvc.perform(get("/api/sys-settings?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(sysSettings.getId().intValue())))
            .andExpect(jsonPath("$.[*].siteTitle").value(hasItem(DEFAULT_SITE_TITLE)))
            .andExpect(jsonPath("$.[*].herderTitle").value(hasItem(DEFAULT_HERDER_TITLE)))
            .andExpect(jsonPath("$.[*].herderLogo").value(hasItem(DEFAULT_HERDER_LOGO)))
            .andExpect(jsonPath("$.[*].locale").value(hasItem(DEFAULT_LOCALE)))
            .andExpect(jsonPath("$.[*].timeZone").value(hasItem(DEFAULT_TIME_ZONE)))
            .andExpect(jsonPath("$.[*].otherContentType").value(hasItem(DEFAULT_OTHER_CONTENT_TYPE)))
            .andExpect(jsonPath("$.[*].other").value(hasItem(Base64Utils.encodeToString(DEFAULT_OTHER))))
            .andExpect(jsonPath("$.[*].tenantId").value(hasItem(DEFAULT_TENANT_ID.intValue())));
    }
    
    @Test
    @Transactional
    public void getSysSettings() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get the sysSettings
        restSysSettingsMockMvc.perform(get("/api/sys-settings/{id}", sysSettings.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(sysSettings.getId().intValue()))
            .andExpect(jsonPath("$.siteTitle").value(DEFAULT_SITE_TITLE))
            .andExpect(jsonPath("$.herderTitle").value(DEFAULT_HERDER_TITLE))
            .andExpect(jsonPath("$.herderLogo").value(DEFAULT_HERDER_LOGO))
            .andExpect(jsonPath("$.locale").value(DEFAULT_LOCALE))
            .andExpect(jsonPath("$.timeZone").value(DEFAULT_TIME_ZONE))
            .andExpect(jsonPath("$.otherContentType").value(DEFAULT_OTHER_CONTENT_TYPE))
            .andExpect(jsonPath("$.other").value(Base64Utils.encodeToString(DEFAULT_OTHER)))
            .andExpect(jsonPath("$.tenantId").value(DEFAULT_TENANT_ID.intValue()));
    }


    @Test
    @Transactional
    public void getSysSettingsByIdFiltering() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        Long id = sysSettings.getId();

        defaultSysSettingsShouldBeFound("id.equals=" + id);
        defaultSysSettingsShouldNotBeFound("id.notEquals=" + id);

        defaultSysSettingsShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultSysSettingsShouldNotBeFound("id.greaterThan=" + id);

        defaultSysSettingsShouldBeFound("id.lessThanOrEqual=" + id);
        defaultSysSettingsShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle equals to DEFAULT_SITE_TITLE
        defaultSysSettingsShouldBeFound("siteTitle.equals=" + DEFAULT_SITE_TITLE);

        // Get all the sysSettingsList where siteTitle equals to UPDATED_SITE_TITLE
        defaultSysSettingsShouldNotBeFound("siteTitle.equals=" + UPDATED_SITE_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle not equals to DEFAULT_SITE_TITLE
        defaultSysSettingsShouldNotBeFound("siteTitle.notEquals=" + DEFAULT_SITE_TITLE);

        // Get all the sysSettingsList where siteTitle not equals to UPDATED_SITE_TITLE
        defaultSysSettingsShouldBeFound("siteTitle.notEquals=" + UPDATED_SITE_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle in DEFAULT_SITE_TITLE or UPDATED_SITE_TITLE
        defaultSysSettingsShouldBeFound("siteTitle.in=" + DEFAULT_SITE_TITLE + "," + UPDATED_SITE_TITLE);

        // Get all the sysSettingsList where siteTitle equals to UPDATED_SITE_TITLE
        defaultSysSettingsShouldNotBeFound("siteTitle.in=" + UPDATED_SITE_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle is not null
        defaultSysSettingsShouldBeFound("siteTitle.specified=true");

        // Get all the sysSettingsList where siteTitle is null
        defaultSysSettingsShouldNotBeFound("siteTitle.specified=false");
    }
                @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle contains DEFAULT_SITE_TITLE
        defaultSysSettingsShouldBeFound("siteTitle.contains=" + DEFAULT_SITE_TITLE);

        // Get all the sysSettingsList where siteTitle contains UPDATED_SITE_TITLE
        defaultSysSettingsShouldNotBeFound("siteTitle.contains=" + UPDATED_SITE_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsBySiteTitleNotContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where siteTitle does not contain DEFAULT_SITE_TITLE
        defaultSysSettingsShouldNotBeFound("siteTitle.doesNotContain=" + DEFAULT_SITE_TITLE);

        // Get all the sysSettingsList where siteTitle does not contain UPDATED_SITE_TITLE
        defaultSysSettingsShouldBeFound("siteTitle.doesNotContain=" + UPDATED_SITE_TITLE);
    }


    @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle equals to DEFAULT_HERDER_TITLE
        defaultSysSettingsShouldBeFound("herderTitle.equals=" + DEFAULT_HERDER_TITLE);

        // Get all the sysSettingsList where herderTitle equals to UPDATED_HERDER_TITLE
        defaultSysSettingsShouldNotBeFound("herderTitle.equals=" + UPDATED_HERDER_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle not equals to DEFAULT_HERDER_TITLE
        defaultSysSettingsShouldNotBeFound("herderTitle.notEquals=" + DEFAULT_HERDER_TITLE);

        // Get all the sysSettingsList where herderTitle not equals to UPDATED_HERDER_TITLE
        defaultSysSettingsShouldBeFound("herderTitle.notEquals=" + UPDATED_HERDER_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle in DEFAULT_HERDER_TITLE or UPDATED_HERDER_TITLE
        defaultSysSettingsShouldBeFound("herderTitle.in=" + DEFAULT_HERDER_TITLE + "," + UPDATED_HERDER_TITLE);

        // Get all the sysSettingsList where herderTitle equals to UPDATED_HERDER_TITLE
        defaultSysSettingsShouldNotBeFound("herderTitle.in=" + UPDATED_HERDER_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle is not null
        defaultSysSettingsShouldBeFound("herderTitle.specified=true");

        // Get all the sysSettingsList where herderTitle is null
        defaultSysSettingsShouldNotBeFound("herderTitle.specified=false");
    }
                @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle contains DEFAULT_HERDER_TITLE
        defaultSysSettingsShouldBeFound("herderTitle.contains=" + DEFAULT_HERDER_TITLE);

        // Get all the sysSettingsList where herderTitle contains UPDATED_HERDER_TITLE
        defaultSysSettingsShouldNotBeFound("herderTitle.contains=" + UPDATED_HERDER_TITLE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderTitleNotContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderTitle does not contain DEFAULT_HERDER_TITLE
        defaultSysSettingsShouldNotBeFound("herderTitle.doesNotContain=" + DEFAULT_HERDER_TITLE);

        // Get all the sysSettingsList where herderTitle does not contain UPDATED_HERDER_TITLE
        defaultSysSettingsShouldBeFound("herderTitle.doesNotContain=" + UPDATED_HERDER_TITLE);
    }


    @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo equals to DEFAULT_HERDER_LOGO
        defaultSysSettingsShouldBeFound("herderLogo.equals=" + DEFAULT_HERDER_LOGO);

        // Get all the sysSettingsList where herderLogo equals to UPDATED_HERDER_LOGO
        defaultSysSettingsShouldNotBeFound("herderLogo.equals=" + UPDATED_HERDER_LOGO);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo not equals to DEFAULT_HERDER_LOGO
        defaultSysSettingsShouldNotBeFound("herderLogo.notEquals=" + DEFAULT_HERDER_LOGO);

        // Get all the sysSettingsList where herderLogo not equals to UPDATED_HERDER_LOGO
        defaultSysSettingsShouldBeFound("herderLogo.notEquals=" + UPDATED_HERDER_LOGO);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo in DEFAULT_HERDER_LOGO or UPDATED_HERDER_LOGO
        defaultSysSettingsShouldBeFound("herderLogo.in=" + DEFAULT_HERDER_LOGO + "," + UPDATED_HERDER_LOGO);

        // Get all the sysSettingsList where herderLogo equals to UPDATED_HERDER_LOGO
        defaultSysSettingsShouldNotBeFound("herderLogo.in=" + UPDATED_HERDER_LOGO);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo is not null
        defaultSysSettingsShouldBeFound("herderLogo.specified=true");

        // Get all the sysSettingsList where herderLogo is null
        defaultSysSettingsShouldNotBeFound("herderLogo.specified=false");
    }
                @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo contains DEFAULT_HERDER_LOGO
        defaultSysSettingsShouldBeFound("herderLogo.contains=" + DEFAULT_HERDER_LOGO);

        // Get all the sysSettingsList where herderLogo contains UPDATED_HERDER_LOGO
        defaultSysSettingsShouldNotBeFound("herderLogo.contains=" + UPDATED_HERDER_LOGO);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByHerderLogoNotContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where herderLogo does not contain DEFAULT_HERDER_LOGO
        defaultSysSettingsShouldNotBeFound("herderLogo.doesNotContain=" + DEFAULT_HERDER_LOGO);

        // Get all the sysSettingsList where herderLogo does not contain UPDATED_HERDER_LOGO
        defaultSysSettingsShouldBeFound("herderLogo.doesNotContain=" + UPDATED_HERDER_LOGO);
    }


    @Test
    @Transactional
    public void getAllSysSettingsByLocaleIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale equals to DEFAULT_LOCALE
        defaultSysSettingsShouldBeFound("locale.equals=" + DEFAULT_LOCALE);

        // Get all the sysSettingsList where locale equals to UPDATED_LOCALE
        defaultSysSettingsShouldNotBeFound("locale.equals=" + UPDATED_LOCALE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByLocaleIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale not equals to DEFAULT_LOCALE
        defaultSysSettingsShouldNotBeFound("locale.notEquals=" + DEFAULT_LOCALE);

        // Get all the sysSettingsList where locale not equals to UPDATED_LOCALE
        defaultSysSettingsShouldBeFound("locale.notEquals=" + UPDATED_LOCALE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByLocaleIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale in DEFAULT_LOCALE or UPDATED_LOCALE
        defaultSysSettingsShouldBeFound("locale.in=" + DEFAULT_LOCALE + "," + UPDATED_LOCALE);

        // Get all the sysSettingsList where locale equals to UPDATED_LOCALE
        defaultSysSettingsShouldNotBeFound("locale.in=" + UPDATED_LOCALE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByLocaleIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale is not null
        defaultSysSettingsShouldBeFound("locale.specified=true");

        // Get all the sysSettingsList where locale is null
        defaultSysSettingsShouldNotBeFound("locale.specified=false");
    }
                @Test
    @Transactional
    public void getAllSysSettingsByLocaleContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale contains DEFAULT_LOCALE
        defaultSysSettingsShouldBeFound("locale.contains=" + DEFAULT_LOCALE);

        // Get all the sysSettingsList where locale contains UPDATED_LOCALE
        defaultSysSettingsShouldNotBeFound("locale.contains=" + UPDATED_LOCALE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByLocaleNotContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where locale does not contain DEFAULT_LOCALE
        defaultSysSettingsShouldNotBeFound("locale.doesNotContain=" + DEFAULT_LOCALE);

        // Get all the sysSettingsList where locale does not contain UPDATED_LOCALE
        defaultSysSettingsShouldBeFound("locale.doesNotContain=" + UPDATED_LOCALE);
    }


    @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone equals to DEFAULT_TIME_ZONE
        defaultSysSettingsShouldBeFound("timeZone.equals=" + DEFAULT_TIME_ZONE);

        // Get all the sysSettingsList where timeZone equals to UPDATED_TIME_ZONE
        defaultSysSettingsShouldNotBeFound("timeZone.equals=" + UPDATED_TIME_ZONE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone not equals to DEFAULT_TIME_ZONE
        defaultSysSettingsShouldNotBeFound("timeZone.notEquals=" + DEFAULT_TIME_ZONE);

        // Get all the sysSettingsList where timeZone not equals to UPDATED_TIME_ZONE
        defaultSysSettingsShouldBeFound("timeZone.notEquals=" + UPDATED_TIME_ZONE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone in DEFAULT_TIME_ZONE or UPDATED_TIME_ZONE
        defaultSysSettingsShouldBeFound("timeZone.in=" + DEFAULT_TIME_ZONE + "," + UPDATED_TIME_ZONE);

        // Get all the sysSettingsList where timeZone equals to UPDATED_TIME_ZONE
        defaultSysSettingsShouldNotBeFound("timeZone.in=" + UPDATED_TIME_ZONE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone is not null
        defaultSysSettingsShouldBeFound("timeZone.specified=true");

        // Get all the sysSettingsList where timeZone is null
        defaultSysSettingsShouldNotBeFound("timeZone.specified=false");
    }
                @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone contains DEFAULT_TIME_ZONE
        defaultSysSettingsShouldBeFound("timeZone.contains=" + DEFAULT_TIME_ZONE);

        // Get all the sysSettingsList where timeZone contains UPDATED_TIME_ZONE
        defaultSysSettingsShouldNotBeFound("timeZone.contains=" + UPDATED_TIME_ZONE);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTimeZoneNotContainsSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where timeZone does not contain DEFAULT_TIME_ZONE
        defaultSysSettingsShouldNotBeFound("timeZone.doesNotContain=" + DEFAULT_TIME_ZONE);

        // Get all the sysSettingsList where timeZone does not contain UPDATED_TIME_ZONE
        defaultSysSettingsShouldBeFound("timeZone.doesNotContain=" + UPDATED_TIME_ZONE);
    }


    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId equals to DEFAULT_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.equals=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId equals to UPDATED_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.equals=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId not equals to DEFAULT_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.notEquals=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId not equals to UPDATED_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.notEquals=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsInShouldWork() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId in DEFAULT_TENANT_ID or UPDATED_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.in=" + DEFAULT_TENANT_ID + "," + UPDATED_TENANT_ID);

        // Get all the sysSettingsList where tenantId equals to UPDATED_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.in=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId is not null
        defaultSysSettingsShouldBeFound("tenantId.specified=true");

        // Get all the sysSettingsList where tenantId is null
        defaultSysSettingsShouldNotBeFound("tenantId.specified=false");
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId is greater than or equal to DEFAULT_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.greaterThanOrEqual=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId is greater than or equal to UPDATED_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.greaterThanOrEqual=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId is less than or equal to DEFAULT_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.lessThanOrEqual=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId is less than or equal to SMALLER_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.lessThanOrEqual=" + SMALLER_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsLessThanSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId is less than DEFAULT_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.lessThan=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId is less than UPDATED_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.lessThan=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllSysSettingsByTenantIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        // Get all the sysSettingsList where tenantId is greater than DEFAULT_TENANT_ID
        defaultSysSettingsShouldNotBeFound("tenantId.greaterThan=" + DEFAULT_TENANT_ID);

        // Get all the sysSettingsList where tenantId is greater than SMALLER_TENANT_ID
        defaultSysSettingsShouldBeFound("tenantId.greaterThan=" + SMALLER_TENANT_ID);
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultSysSettingsShouldBeFound(String filter) throws Exception {
        restSysSettingsMockMvc.perform(get("/api/sys-settings?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(sysSettings.getId().intValue())))
            .andExpect(jsonPath("$.[*].siteTitle").value(hasItem(DEFAULT_SITE_TITLE)))
            .andExpect(jsonPath("$.[*].herderTitle").value(hasItem(DEFAULT_HERDER_TITLE)))
            .andExpect(jsonPath("$.[*].herderLogo").value(hasItem(DEFAULT_HERDER_LOGO)))
            .andExpect(jsonPath("$.[*].locale").value(hasItem(DEFAULT_LOCALE)))
            .andExpect(jsonPath("$.[*].timeZone").value(hasItem(DEFAULT_TIME_ZONE)))
            .andExpect(jsonPath("$.[*].otherContentType").value(hasItem(DEFAULT_OTHER_CONTENT_TYPE)))
            .andExpect(jsonPath("$.[*].other").value(hasItem(Base64Utils.encodeToString(DEFAULT_OTHER))))
            .andExpect(jsonPath("$.[*].tenantId").value(hasItem(DEFAULT_TENANT_ID.intValue())));

        // Check, that the count call also returns 1
        restSysSettingsMockMvc.perform(get("/api/sys-settings/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultSysSettingsShouldNotBeFound(String filter) throws Exception {
        restSysSettingsMockMvc.perform(get("/api/sys-settings?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restSysSettingsMockMvc.perform(get("/api/sys-settings/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingSysSettings() throws Exception {
        // Get the sysSettings
        restSysSettingsMockMvc.perform(get("/api/sys-settings/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateSysSettings() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        int databaseSizeBeforeUpdate = sysSettingsRepository.findAll().size();

        // Update the sysSettings
        SysSettings updatedSysSettings = sysSettingsRepository.findById(sysSettings.getId()).get();
        // Disconnect from session so that the updates on updatedSysSettings are not directly saved in db
        em.detach(updatedSysSettings);
        updatedSysSettings
            .siteTitle(UPDATED_SITE_TITLE)
            .herderTitle(UPDATED_HERDER_TITLE)
            .herderLogo(UPDATED_HERDER_LOGO)
            .locale(UPDATED_LOCALE)
            .timeZone(UPDATED_TIME_ZONE)
            .other(UPDATED_OTHER)
            .otherContentType(UPDATED_OTHER_CONTENT_TYPE)
            .tenantId(UPDATED_TENANT_ID);
        SysSettingsDTO sysSettingsDTO = sysSettingsMapper.toDto(updatedSysSettings);

        restSysSettingsMockMvc.perform(put("/api/sys-settings").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(sysSettingsDTO)))
            .andExpect(status().isOk());

        // Validate the SysSettings in the database
        List<SysSettings> sysSettingsList = sysSettingsRepository.findAll();
        assertThat(sysSettingsList).hasSize(databaseSizeBeforeUpdate);
        SysSettings testSysSettings = sysSettingsList.get(sysSettingsList.size() - 1);
        assertThat(testSysSettings.getSiteTitle()).isEqualTo(UPDATED_SITE_TITLE);
        assertThat(testSysSettings.getHerderTitle()).isEqualTo(UPDATED_HERDER_TITLE);
        assertThat(testSysSettings.getHerderLogo()).isEqualTo(UPDATED_HERDER_LOGO);
        assertThat(testSysSettings.getLocale()).isEqualTo(UPDATED_LOCALE);
        assertThat(testSysSettings.getTimeZone()).isEqualTo(UPDATED_TIME_ZONE);
        assertThat(testSysSettings.getOther()).isEqualTo(UPDATED_OTHER);
        assertThat(testSysSettings.getOtherContentType()).isEqualTo(UPDATED_OTHER_CONTENT_TYPE);
        assertThat(testSysSettings.getTenantId()).isEqualTo(UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void updateNonExistingSysSettings() throws Exception {
        int databaseSizeBeforeUpdate = sysSettingsRepository.findAll().size();

        // Create the SysSettings
        SysSettingsDTO sysSettingsDTO = sysSettingsMapper.toDto(sysSettings);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restSysSettingsMockMvc.perform(put("/api/sys-settings").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(sysSettingsDTO)))
            .andExpect(status().isBadRequest());

        // Validate the SysSettings in the database
        List<SysSettings> sysSettingsList = sysSettingsRepository.findAll();
        assertThat(sysSettingsList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteSysSettings() throws Exception {
        // Initialize the database
        sysSettingsRepository.saveAndFlush(sysSettings);

        int databaseSizeBeforeDelete = sysSettingsRepository.findAll().size();

        // Delete the sysSettings
        restSysSettingsMockMvc.perform(delete("/api/sys-settings/{id}", sysSettings.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<SysSettings> sysSettingsList = sysSettingsRepository.findAll();
        assertThat(sysSettingsList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
